Find the Kth max and min element of an array